import 'package:get_storage/get_storage.dart';
import 'package:hixing_app/extensions/str_ext.dart';
import 'package:hixing_app/utils/export_utils.dart';
import 'package:hixing_app/utils/storage/sharedpre_storage.dart';

class GetAppConfigStorage {
// 缓存模块的key
  static const _storageBoxKey = "app_app_config_storage_container";
  static final GetStorage _appConfigStorage = GetStorage(_storageBoxKey);
  static const int maxHeightList = 50;

  static GetStorage get appConfigStorage => _appConfigStorage;

  static init() {
    GetStorage.init(_storageBoxKey);
  }

  // 详情页图片显示模式
  static const String detailImgModekey = "detailImgMode";

  String? get detailImgMode => appConfigStorage.read<String>(detailImgModekey);

  // 0： 普通模式， 1：3D模式
  Future<void> setDetailImgModel(String val) async {
    logs("设置3d模式展示类型===============");
    await appConfigStorage.write(detailImgModekey, val);
  }

//-----------------------  // 详情页图片显示模式--------end
  // 储存详情图片计算的高度
  static const String detailHeightListKey = "detailHeightList";

  List get detailHeightList =>
      appConfigStorage.read<List>(detailHeightListKey) ?? [];

  //储存详情图片计算过的高度尺寸，下次访问获取缓存的图片高度
  Future<void> setHeightList(Map<dynamic, dynamic> item) async {
    List _arr = detailHeightList;
    if (_arr.length > maxHeightList) {
      _arr.removeAt(0);
    }
    if (_arr.contains(item)) return;
    _arr.add(item);
    await appConfigStorage.write(detailHeightListKey, _arr);
  }

  Future<void> removeHeightList() async {
    await appConfigStorage.remove(detailHeightListKey);
  }

//-----------------------  // 储存详情图片计算的高度--------end

  // app 开屏公告页跳转外链地址
  static const String appOpenScreenJumpUrlKey = "appOpenScreenJumpUrl";

  String? get appOpenScreenJumpUrl =>
      appConfigStorage.read<String>(appOpenScreenJumpUrlKey);

  //
  Future<void> setAppOpenScreenJumpUrl(String url) async {
    await appConfigStorage.write(appOpenScreenJumpUrlKey, url);
  }

  Future<void> removeAppOpenScreenJumpUrl() async {
    await appConfigStorage.remove(appOpenScreenJumpUrlKey);
  }

//-----------------------  //  app  开屏公告页跳转外链地址--------end

// app 开屏公告页图片地址
  static const String appOpenScreenUrlKey = "appOpenScreenUrl";

  String? get appOpenScreenUrl =>
      appConfigStorage.read<String>(appOpenScreenUrlKey);

  //
  Future<void> setAppOpenScreenUrl(String url) async {
    await appConfigStorage.write(appOpenScreenUrlKey, url);
  }

  Future<void> removeAppOpenScreenUrl() async {
    await appConfigStorage.remove(appOpenScreenUrlKey);
  }

//-----------------------  //  app 开屏公告页图片地址--------end

  //-----------------------  //  是否第一次显示头发pfp操作 --------end

// app 开屏公告页图片地址
  static const String isShowPfpGuideKey = "isShowPfpGuide";

  bool? get isShowPfpGuide => appConfigStorage.read<bool>(isShowPfpGuideKey);

  //
  Future<void> setIsShowPfpGuide(bool isShow) async {
    await appConfigStorage.write(isShowPfpGuideKey, isShow);
  }

  Future<void> removeIsShowPfpGuide() async {
    await appConfigStorage.remove(isShowPfpGuideKey);
  }

//-----------------------  //  app 开屏公告页图片地址--------end

  // app 更新信息
  static const String appUpdateInfoKey = "appUpdateInfo";

  Map<String, dynamic>? get appUpdateInfo =>
      appConfigStorage.read<Map<String, dynamic>>(appUpdateInfoKey);

  //
  Future<void> setAppUpdateInfo(dynamic val) async {
    await appConfigStorage.write(appUpdateInfoKey, val);
  }

  Future<void> removeAppUpdateInfo() async {
    await appConfigStorage.remove(appUpdateInfoKey);
  }

  //-----------------------  // app 更新信息--------end
  Future<void> remove(String key) async {
    await appConfigStorage.remove(key);
  }

  Future<void> removeAll() async {
    appConfigStorage.erase();
  }
}
